package com.zry.service.blogCategoty;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zry.entity.BlogCategory;
import com.zry.mapper.BlogCategoryMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author Zry
 */
@Service
@Slf4j
public class IBlogCategoryServiceImpl extends ServiceImpl<BlogCategoryMapper, BlogCategory> implements IBlogCategoryService{

    @Override
    public List<BlogCategory> findBlogCategories() {
        QueryWrapper<BlogCategory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status",1).orderByAsc("sorted");

        // 使用stream 流排序
        //if(!CollectionUtils.isEmpty(categoryList)) {
        //    categoryList = categoryList.stream().sorted((a, b) -> a.getSorted() - b.getSorted()).collect(Collectors.toList());
        //}

        return this.list(queryWrapper);
    }
}
